home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
gonza
/
key.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-08
|
10KB
|
469 lines
/*
Key Master V0.1
presented by Gonza ( TOOLS ).
*/
#include <egb.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <fmc.h>
char gwork[EgbWorkSize], buf[300000];
char filename[80],kindname[80],data[100][100],edata[100][100];
int kind, dataend, max, err;
time_t starttime, endtime;
unsigned int alltime;
enum coltyp { black, ltcha, tuchi, dkgreen, blackgreen, haiblue,
ki, ltblue, akamura, red, birizi, uguisu, ltgreen,
whitecha, dkcha, white } color;
void palette_set( int color_num, int red, int green, int blue );
void palette_init( void );
void boxful(int x1, int y1, int x2, int y2, int c);
void symbol(int x, int y, char *s, int c);
void lineboxful(int x1, int y1, int x2, int y2, int c1, int c2);
void windowbox(int x1, int y1, int x2, int y2 );
void error( int i );
void main( void );
void mes( char *s, int c );
void retkey( void );
void put( int x1, int y1, int x2, int y2 );
void get( int x1, int y1, int x2, int y2 );
void opening( void );
int mes2( char *s, int c );
int set_x( char *s );
void fileopen( void );
void exec( void );
void result( void );
void xor_boxful( int x1, int y1, int x2, int y2, int c );
void main( void )
{
int max;
EGB_init( gwork, sizeof(gwork) );
KYB_init();
KYB_setcode( 0x0000 );
KYB_lock( 1 );
KYB_clic( 1 );
KYB_clrbuf();
palette_init();
KYB_lock( 0 );
opening();
fileopen();
exec();
result();
}
/* オープニング */
void opening( void )
{
int k = 0;
boxful( 0, 0, 639, 479, dkgreen );
mes( "キーボードを準備してリターンキーを押してください", blackgreen );
mes( "キーボード打ち込み速度の測定 v0.1", blackgreen );
mes( "Programmed by GONZA ( tools )", blackgreen );
mes( "文章は 一般文(1), 一般文(2), 一般文(3) の3つを用意しました", blackgreen );
mes( "デフォルトは英小モードです", akamura );
mes( "行末で改行する必要はありません", akamura );
k = mes2( "選択してください ( 1: 一般文(1), 2:一般文(2), 3:一般文(3) )", akamura );
switch( k )
{
case '1':
strcpy( filename, "english.dat" );
strcpy( kindname, "一般文(1)" );
kind = 1;
break;
case '2':
strcpy( filename, "english2.dat" );
strcpy( kindname, "一般文(2)" );
kind = 2;
break;
case '3':
strcpy( filename, "english3.dat" );
strcpy( kindname, "一般文(3)" );
kind = 3;
break;
}
mes( "リターンキーを押すと測定開始です", akamura );
}
/* データファイルのオープン */
void fileopen( void )
{
FILE *fp;
int i = 0;
int len;
if(( fp = fopen( filename, "r" ) ) == NULL )
error( 1 );
while( fgets( data[i], 256, fp ) != NULL )
{
len = strlen( data[i] );
data[ i++ ][ len-1 ] = '\0';
}
dataend = i - 1;
fclose( fp );
}
/* タイプ速度測定 */
void exec( void )
{
int cn,len,x,er = 0,all = 0, i, mj = 0;
unsigned int moji, code, dmy, ipt;
char s[5],ss[80],sss[80];
for( cn=0; cn<=dataend; cn++ )
{
len = strlen( data[cn] ) - 1;
for( x=0; x<=len; x++ )
all++;
}
time( &starttime );
for( cn=0; cn<=dataend; cn++ )
{
sprintf( ss, "%d", cn );
strcat( ss, "行 / " );
sprintf( sss, "%d", dataend );
strcat( sss, "行" );
get( 10, 100, 634, 384 );
windowbox( 10, 100, 630, 380 );
symbol( 34, 116, data[cn], black );
symbol( 300, 176, ss, tuchi );
symbol( 400, 176, sss, blackgreen );
len = strlen( data[cn] ) - 1;
for( x=0; x<=len; x++ )
{
mj++;
xor_boxful( 34+x*8, 148, 34+8+x*8, 148+16, ki );
/* symbol( 34 + x*8, 148, "_", red ); */
KYB_clrbuf();
moji = KYB_read( 0, &code );
BPB_freeon( 10, 48 );
dmy = moji<<9;
dmy = dmy>>9;
ipt = dmy;
xor_boxful( 34+x*8, 148, 34+8+x*8, 148+16, ki );
/* symbol( 34 + x*8, 148, "_", WHITE ); */
s[0] = (char)ipt;
s[1] = '\0';
if( (char)ipt == data[cn][x] )
{
symbol( 34 + x*8, 148, s, ltblue );
edata[cn][x] = (char)ipt;
}
else
{
symbol( 34 + x*8, 148, s, red );
edata[cn][x] = (char)ipt;
er++;
}
}
edata[cn][x+1] = '\0';
put( 10, 100, 634, 384 );
}
max = all;
err = er;
time( &endtime );
alltime = (unsigned int)difftime( endtime, starttime );
}
/* 結果報告 */
void result( void )
{
int i, sc;
double ad, mx, ti, er;
char s[80],dmy[40];
for( i=0; i<=39; i++ )
dmy[i] = '\0';
mes( "ただいまの結果を報告いたします", blackgreen );
strcpy( s, "コース名: " );
strcat( s, kindname );
strcat( s, ", Time: " );
sprintf( dmy, "%d", alltime );
strcat( s, dmy );
strcat( s, ", Error: " );
for( i=0; i<=39; i++ )
dmy[i] = '\0';
sprintf( dmy, "%d", err );
strcat( s, dmy );
strcat( s, " / " );
sprintf( dmy, "%d", max );
strcat( s, dmy );
strcat( s, "letters. " );
mes( s, dkcha );
mx = (double)max;
ti = (double)alltime;
er = (double)err;
ad = mx/ti;
sc = (int)( (mx-er)/mx * ad * 100.00 );
sprintf( dmy, "%f", ad );
strcpy( s, "タイプ速度: 毎秒 " );
strcat( s, dmy );
strcat( s, "文字" );
mes( s, dkcha );
sprintf( dmy, "%d", sc );
strcpy( s, "総合評価: " );
strcat( s, dmy );
strcat( s, "ポイントでした" );
mes( s, akamura );
mes( "では、またの御利用をお待ちいたしております。", blackgreen );
}
/* リターンキー待ち */
void retkey( void )
{
unsigned int moji, code, dmy = '\0';
KYB_clrbuf();
while( dmy != 0x0d )
{
moji = KYB_read( 0, &code );
dmy = moji<<9;
dmy = dmy>>9;
}
}
/* メッセージ */
void mes( char *s, int c )
{
int len, x1, y1, x2, y2;
len = strlen( s );
x1 = (int)( 640 - len*8 ) / 2 - 48;
y1 = 200;
x2 = 640 - x1;
y2 = 280;
get( x1, y1, x2+4, y2+4 );
windowbox( x1, y1, x2, y2 );
symbol( x1 + 48, 232, s, c );
retkey();
put( x1, y1, x2+4, y2+4 );
}
/* メッセージ2 */
int mes2( char *s, int c )
{
int len, x1, y1, x2, y2;
unsigned int moji, code, k =0;
char ss[5];
len = strlen( s );
x1 = (int)( 640 - len*8 ) / 2 - 48;
y1 = 200;
x2 = 640 - x1;
y2 = 280;
get( x1, y1, x2+4, y2+4 );
windowbox( x1, y1, x2, y2 );
symbol( x1 + 48, 232, s, c );
while( k!='1' && k!='2' && k!='3' )
{
moji = KYB_read( 0, &code );
KYB_clrbuf();
k = moji<<8;
k = k>>8;
}
put( x1, y1, x2+4, y2+4 );
return( k );
}
/* エラー処理 */
void error( int i )
{
int x = 0;
char s[121];
windowbox( 120, 200, 520, 280 );
switch( i )
{
case 1:
strcpy( s, "データファイルがありません" );
break;
}
x = set_x( s );
symbol( x, 232, s, red );
retkey();
exit( 1 );
}
int set_x( char *s )
{
int i,x;
i = strlen( s );
x = 120 + ( 400 - i * 8 ) / 2;
return( x );
}
/* Xor処理ボックスフル */
void xor_boxful( int x1, int y1, int x2, int y2, int c )
{
char para[10];
EGB_color(gwork, 0, c);
EGB_color(gwork, 2, c);
EGB_paintMode( gwork, 0x22 );
EGB_writeMode( gwork, 4 );
WORD(para + 0) = x1;
WORD(para + 2) = y1;
WORD(para + 4) = x2;
WORD(para + 6) = y2;
EGB_rectangle(gwork, para);
EGB_writeMode( gwork, 0 );
}
/* パステルパレット設定 */
void palette_init( void )
{
palette_set( black, 0, 0, 0 );
palette_set( ltcha, 9, 8, 5 );
palette_set( tuchi, 7, 5, 2 );
palette_set( dkgreen, 7, 9, 7 );
palette_set( blackgreen, 0, 5, 2 );
palette_set( haiblue, 9, 10, 11 );
palette_set( ki, 15, 15, 7 );
palette_set( ltblue, 9, 9, 13 );
palette_set( akamura, 12, 3, 8 );
palette_set( red, 15, 3, 0 );
palette_set( birizi, 0, 10, 5 );
palette_set( uguisu, 7, 9, 3 );
palette_set( ltgreen, 9, 13, 10 );
palette_set( whitecha, 14, 14, 12 );
palette_set( dkcha, 5, 3, 0 );
palette_set( white, 15, 15, 15 );
}
/* オリジナルパレット設定 */
void palette_set( int color_num, int red, int green, int blue )
{
char para[64];
DWORD( para + 0 ) = 1;
DWORD( para + 4 ) = color_num;
BYTE( para + 8 ) = blue*17;
BYTE( para + 9 ) = red*17;
BYTE( para + 10 ) = green*17;
BYTE( para + 11 ) = 0;
EGB_palette( gwork, 1, para );
}
/* ボックスフル */
void boxful(int x1, int y1, int x2, int y2, int c)
{
char para[10];
EGB_color(gwork, 0, c);
EGB_color(gwork, 2, c);
EGB_paintMode(gwork, 0x22);
WORD(para + 0) = x1;
WORD(para + 2) = y1;
WORD(para + 4) = x2;
WORD(para + 6) = y2;
EGB_rectangle(gwork, para);
}
void get( int x1, int y1, int x2, int y2 )
{
char para[64];
DWORD( para + 0 ) = (unsigned int)buf;
WORD( para + 4 ) = 0x14;
WORD( para + 6 ) = x1;
WORD( para + 8 ) = y1;
WORD( para +10 ) = x2;
WORD( para +12 ) = y2;
EGB_getBlock( gwork, para );
}
void put( int x1, int y1, int x2, int y2 )
{
char para[64];
DWORD( para + 0 ) = (unsigned int)buf;
WORD( para + 4 ) = 0x14;
WORD( para + 6 ) = x1;
WORD( para + 8 ) = y1;
WORD( para +10 ) = x2;
WORD( para +12 ) = y2;
EGB_putBlock( gwork, 0, para );
}
/* 枠付ボックスフル */
void lineboxful(int x1, int y1, int x2, int y2, int c1, int c2)
{
char para[10];
EGB_color(gwork, 0, c1);
EGB_color(gwork, 2, c2);
EGB_paintMode(gwork, 0x22);
WORD(para + 0) = x1;
WORD(para + 2) = y1;
WORD(para + 4) = x2;
WORD(para + 6) = y2;
EGB_rectangle(gwork, para);
}
/* tmenu v1.1式 ウインドウ */
void windowbox( int x1, int y1, int x2, int y2 )
{
char para[10];
EGB_color( gwork, 0, dkcha );
EGB_color( gwork, 2, dkcha );
EGB_paintMode( gwork, 0x22 );
WORD(para + 0) = x1 + 4 ;
WORD(para + 2) = y1 + 4 ;
WORD(para + 4) = x2 + 4 ;
WORD(para + 6) = y2 + 4 ;
EGB_rectangle( gwork, para );
EGB_color( gwork, 2, whitecha );
WORD(para + 0) = x1;
WORD(para + 2) = y1;
WORD(para + 4) = x2;
WORD(para + 6) = y2;
EGB_rectangle( gwork, para );
}
/* ノーマルシンボル */
void symbol(int x, int y, char *s, int c)
{
char para[256];
int len;
int i;
EGB_color(gwork, 0, c);
len = strlen(s);
WORD(para + 0) = x;
WORD(para + 2) = y + 16;
WORD(para + 4) = len;
for (i = 6; i < len + 6; i++)
para[i] = s[i - 6];
para[i] = '\0';
EGB_sjisString(gwork, para);
}